package com.hsmw.api.controller.biz;

import cn.hutool.core.lang.Assert;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hsmw.api.service.HsmwRoleService;
import com.htn.common.core.utils.StringUtils;
import com.hsmw.domain.form.GetObjectByIdForm;
import com.hsmw.domain.vo.SaveRoleMenuVO;
import com.hsmw.common.base.BaseController;
import com.hsmw.common.base.BasePage;
import com.htn.common.core.base.DataResponse;
import com.hsmw.domain.HsmwRole;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @author WD
 */
@Api(tags = "BIZ-角色管理")
@RestController
@RequestMapping("/api/biz/role")
public class BizRoleController extends BaseController<HsmwRoleService, HsmwRole> {

	@Autowired
	private HsmwRoleService hsmwRoleService;

	/**
	 * 分页
	 *
	 * @param basePage
	 * @return
	 */
	@ApiOperation(value = "获取角色分页列表", notes = "获取角色分页列表", produces = "application/json")
	@PostMapping("/getHsmwRolePage")
	public DataResponse getHsmwRolePage(@RequestBody BasePage<HsmwRole> basePage) {
		IPage page = new Page(basePage.getPageNo(), basePage.getPageSize());
		HsmwRole hsmwRole = basePage.getRequestData();
		Assert.notNull(page.getCurrent(), "页码不能为空");
		Assert.notNull(page.getSize(), "页码不能为空");
		IPage<HsmwRole> data = hsmwRoleService.getHsmwRolePage(page, hsmwRole);
		return new DataResponse(data);
	}

	/**
	 * 获取角色下拉列表
	 *
	 * @return
	 */
	@ApiOperation(value = "获取角色下拉列表", notes = "获取角色下拉列表", produces = "application/json")
	@PostMapping("/getHsmwRoleSelect")
	public DataResponse getHsmwRoleSelect() {
		List data = hsmwRoleService.getHsmwRoleSelect();
		return new DataResponse(data);
	}

	/**
	 * 根据ID查询数据
	 *
	 * @param form
	 * @return
	 */
	@ApiOperation(value = "根据id查询数据", notes = "根据id查询数据", produces = "application/json")
	@PostMapping("/getHsmwRoleById")
	public DataResponse getHsmwRoleById(@RequestBody GetObjectByIdForm form) {
		HsmwRole hsmwRole = hsmwRoleService.getById(form.getKey());
		return new DataResponse(hsmwRole);
	}

	/**
	 * 新增
	 * 修改  必须带ID
	 *
	 * @param hsmwRole
	 * @return
	 */
	@ApiOperation(value = "新增/修改", notes = "新增/修改/逻辑删除", produces = "application/json")
	@PostMapping("/saveOrUpdateHsmwRole")
	public DataResponse saveOrUpdateHsmwRole(@RequestBody HsmwRole hsmwRole) {

		return hsmwRoleService.saveOrUpdateHsmwRole(hsmwRole);
	}

	/**
	 * 设置角色菜单
	 */
	@ApiOperation(value = "设置角色菜单", notes = "设置角色菜单", produces = "application/json")
	@PostMapping("/saveRoMenuTree")
	public DataResponse saveRoMenuTree(@RequestBody @Valid SaveRoleMenuVO saveRoleMenuVo) {
		return hsmwRoleService.saveRoMenuTree(saveRoleMenuVo);
	}


	/**
	 * 删除角色
	 * @param id
	 * @return
	 */
	@ApiOperation(value = "删除角色", notes = "删除角色", produces = "application/json")
	@ApiImplicitParam(name = "角色id",value = "id",dataType = "String",required = true)
	@PostMapping("/deleteRoleById")
	public DataResponse deleteRoleById(String id){

		return hsmwRoleService.deleteRoleById(id);
	}









}
